package com.lt.bcra.controller.questionnaire;


import com.lt.bcra.entity.BcraLifeHabits;
import com.lt.bcra.exception.BaseException;
import com.lt.bcra.service.BcraLifeHabitsService;
import com.lt.bcra.result.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 生活习惯表 前端控制器
 * </p>
 *
 * @author LuoTian
 * @since 2022-05-25
 */
@Api(tags = "3.生活习惯表")
@CrossOrigin //跨域可以前端配置
@RestController
@RequestMapping("bcra/lifeHabits")
public class BcraLifeHabitsController {

    private static Logger log = LoggerFactory.getLogger(BcraLifeHabitsController.class);

    @Autowired
    private BcraLifeHabitsService bcraLifeHabitsService;


    @PostMapping("/creatLifeHabits")
    @ApiOperation("填写生活习惯")
    @ApiParam(value = "bcraLifeHabits")
    public ResultData creatNew(@RequestBody BcraLifeHabits bcraLifeHabits) throws BaseException {
        if (log.isDebugEnabled()) log.debug("创建生活习惯表 BcraLifeHabitsController");

        return bcraLifeHabitsService.saveModule(bcraLifeHabits);
    }

    @PostMapping("/updateLifeHabits")
    @ApiOperation("修改生活习惯")
    @ApiParam(value = "bcraLifeHabits")
    public ResultData update(@RequestBody BcraLifeHabits bcraLifeHabits) throws BaseException {
        if (log.isDebugEnabled()) log.debug("修改生活习惯表 BcraLifeHabitsController");

        return bcraLifeHabitsService.updateModule(bcraLifeHabits);
    }

    @DeleteMapping("/deleteLifeHabits")
    @ApiOperation("删除生活习惯")
    @ApiParam(value = "问卷编号")
    public ResultData delete(String questionnaireCode) throws BaseException{
        if (log.isDebugEnabled()) log.debug("删除生活习惯表 BcraLifeHabitsController");

        return bcraLifeHabitsService.removeByQuesCode(questionnaireCode);
    }

    @GetMapping("/getLifeHabits")
    @ApiOperation("查看生活习惯")
    @ApiParam(value = "问卷编号")
    public ResultData list(String questionnaireCode) throws BaseException{
        if (log.isDebugEnabled()) log.debug("删除生活习惯 BcraLifeHabitsController");

        return bcraLifeHabitsService.selectByQuesCode(questionnaireCode);
    }
}

